package echo.service.impl;

import echo.service.OrderRepository;
import echo.vo.Order;
import echo.vo.OrderStatus;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


/**
 * 内存订单存储
 */
public class MemoryOrderReppository implements OrderRepository {
    private final Map<String, Order> orders = new ConcurrentHashMap<>();

    @Override
    public Order save(Order order) {
        orders.put(order.getOrderId(), order);
        return order;
    }

    @Override
    public Order findById(String orderId) {
        return orders.get(orderId);
    }

    @Override
    public void updateStatus(String orderId, OrderStatus status) {
        Order order=orders.get(orderId);
        if (order!=null){
            order.setStatus(status);
        }
    }

}